﻿
namespace NetROS.Tiers.Windows.Forms
{
	/// <summary>
	/// abstract DokumentZaglavljeSpecDokTip typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class DokumentZaglavljeSpecDokTipDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<DokumentZaglavljeSpecDokTipDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.DokumentZaglavljeSpecDokTip _currentDokumentZaglavljeSpecDokTip = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxDokumentZaglavljeSpecDokTipDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxDokumentZaglavljeSpecDokTipErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxDokumentZaglavljeSpecDokTipBindingSource;
		
		
		/// <summary> 
		/// the DGV column associated with the ID property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIDDataGridViewColumn;
		/// <summary> 
		/// the DGV column associated with the IDDokumentTipOd property
		/// </summary>
		protected System.Windows.Forms.DataGridViewComboBoxColumn uxIDDokumentTipOdDataGridViewColumn;
		/// <summary> 
		/// the DGV column associated with the IDDokumentTipZa property
		/// </summary>
		protected System.Windows.Forms.DataGridViewComboBoxColumn uxIDDokumentTipZaDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
				
		private Entities.TList<Entities.DokumentTip> _IDDokumentTipOdList;
		
		/// <summary> 
		/// The list of selectable DokumentTip
		/// </summary>
		[System.ComponentModel.Category("DropDownList BindingSources")]
		public Entities.TList<Entities.DokumentTip> IDDokumentTipOdList
		{
			get {return this._IDDokumentTipOdList;}
			set 
			{
				this._IDDokumentTipOdList = value;
				this.uxIDDokumentTipOdDataGridViewColumn.DataSource = null;
				this.uxIDDokumentTipOdDataGridViewColumn.DataSource = this._IDDokumentTipOdList;
			}
		}
		
		private bool _allowNewItemInIDDokumentTipOdList;
		
		/// <summary> 
		/// Indicates if user can add an item in the list of DokumentTip
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInIDDokumentTipOdList
		{
			get { return _allowNewItemInIDDokumentTipOdList;}
			set
			{
				this._allowNewItemInIDDokumentTipOdList = value;
				this.uxIDDokumentTipOdDataGridViewColumn.DisplayStyle = value ? System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox : System.Windows.Forms.DataGridViewComboBoxDisplayStyle.DropDownButton;
			}
		}
		
				
		private Entities.TList<Entities.DokumentTip> _IDDokumentTipZaList;
		
		/// <summary> 
		/// The list of selectable DokumentTip
		/// </summary>
		[System.ComponentModel.Category("DropDownList BindingSources")]
		public Entities.TList<Entities.DokumentTip> IDDokumentTipZaList
		{
			get {return this._IDDokumentTipZaList;}
			set 
			{
				this._IDDokumentTipZaList = value;
				this.uxIDDokumentTipZaDataGridViewColumn.DataSource = null;
				this.uxIDDokumentTipZaDataGridViewColumn.DataSource = this._IDDokumentTipZaList;
			}
		}
		
		private bool _allowNewItemInIDDokumentTipZaList;
		
		/// <summary> 
		/// Indicates if user can add an item in the list of DokumentTip
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInIDDokumentTipZaList
		{
			get { return _allowNewItemInIDDokumentTipZaList;}
			set
			{
				this._allowNewItemInIDDokumentTipZaList = value;
				this.uxIDDokumentTipZaDataGridViewColumn.DisplayStyle = value ? System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox : System.Windows.Forms.DataGridViewComboBoxDisplayStyle.DropDownButton;
			}
		}
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.DokumentZaglavljeSpecDokTip> _DokumentZaglavljeSpecDokTipList;
				
		/// <summary> 
		/// The list of DokumentZaglavljeSpecDokTip to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.DokumentZaglavljeSpecDokTip> DokumentZaglavljeSpecDokTipList
		{
			get {return this._DokumentZaglavljeSpecDokTipList;}
			set
			{
				this._DokumentZaglavljeSpecDokTipList = value;
				this.uxDokumentZaglavljeSpecDokTipBindingSource.DataSource = null;
				this.uxDokumentZaglavljeSpecDokTipBindingSource.DataSource = value;
				this.uxDokumentZaglavljeSpecDokTipDataGridView.DataSource = null;
				this.uxDokumentZaglavljeSpecDokTipDataGridView.DataSource = this.uxDokumentZaglavljeSpecDokTipBindingSource;				
				//this.uxDokumentZaglavljeSpecDokTipBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxDokumentZaglavljeSpecDokTipBindingSource_ListChanged);
				this.uxDokumentZaglavljeSpecDokTipBindingSource.CurrentItemChanged += new System.EventHandler(OnDokumentZaglavljeSpecDokTipBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnDokumentZaglavljeSpecDokTipBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentDokumentZaglavljeSpecDokTip = uxDokumentZaglavljeSpecDokTipBindingSource.Current as Entities.DokumentZaglavljeSpecDokTip;
			
			if (_currentDokumentZaglavljeSpecDokTip != null)
			{
				_currentDokumentZaglavljeSpecDokTip.Validate();
			}
			//_DokumentZaglavljeSpecDokTip.Validate();
			OnCurrentEntityChanged();
		}

		//void uxDokumentZaglavljeSpecDokTipBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.DokumentZaglavljeSpecDokTip"/> instance.
		/// </summary>
		public Entities.DokumentZaglavljeSpecDokTip SelectedDokumentZaglavljeSpecDokTip
		{
			get {return this._currentDokumentZaglavljeSpecDokTip;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxDokumentZaglavljeSpecDokTipDataGridView.VirtualMode;}
			set
			{
				this.uxDokumentZaglavljeSpecDokTipDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxDokumentZaglavljeSpecDokTipDataGridView.AllowUserToAddRows;}
			set {this.uxDokumentZaglavljeSpecDokTipDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxDokumentZaglavljeSpecDokTipDataGridView.AllowUserToDeleteRows;}
			set {this.uxDokumentZaglavljeSpecDokTipDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxDokumentZaglavljeSpecDokTipDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxDokumentZaglavljeSpecDokTipDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="DokumentZaglavljeSpecDokTipDataGridViewBase"/> class.
		/// </summary>
		public DokumentZaglavljeSpecDokTipDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxDokumentZaglavljeSpecDokTipDataGridView = new System.Windows.Forms.DataGridView();
			this.uxDokumentZaglavljeSpecDokTipBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxDokumentZaglavljeSpecDokTipErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxIDDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxIDDokumentTipOdDataGridViewColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
			this.uxIDDokumentTipZaDataGridViewColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
			//this.uxIDDokumentTipOdBindingSource = new DokumentTipBindingSource(this.components);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDDokumentTipOdBindingSource)).BeginInit();
			//this.uxIDDokumentTipZaBindingSource = new DokumentTipBindingSource(this.components);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDDokumentTipZaBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentZaglavljeSpecDokTipDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentZaglavljeSpecDokTipBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentZaglavljeSpecDokTipErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxDokumentZaglavljeSpecDokTipErrorProvider
			// 
			this.uxDokumentZaglavljeSpecDokTipErrorProvider.ContainerControl = this;
			this.uxDokumentZaglavljeSpecDokTipErrorProvider.DataSource = this.uxDokumentZaglavljeSpecDokTipBindingSource;						
			// 
			// uxDokumentZaglavljeSpecDokTipDataGridView
			// 
			this.uxDokumentZaglavljeSpecDokTipDataGridView.AutoGenerateColumns = false;
			this.uxDokumentZaglavljeSpecDokTipDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxDokumentZaglavljeSpecDokTipDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxIDDataGridViewColumn,
		this.uxIDDokumentTipOdDataGridViewColumn,
		this.uxIDDokumentTipZaDataGridViewColumn			});
			this.uxDokumentZaglavljeSpecDokTipDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxDokumentZaglavljeSpecDokTipDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxDokumentZaglavljeSpecDokTipDataGridView.Name = "uxDokumentZaglavljeSpecDokTipDataGridView";
			this.uxDokumentZaglavljeSpecDokTipDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxDokumentZaglavljeSpecDokTipDataGridView.TabIndex = 0;	
			this.uxDokumentZaglavljeSpecDokTipDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxDokumentZaglavljeSpecDokTipDataGridView.EnableHeadersVisualStyles = false;
			this.uxDokumentZaglavljeSpecDokTipDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnDokumentZaglavljeSpecDokTipDataGridViewDataError);
			this.uxDokumentZaglavljeSpecDokTipDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnDokumentZaglavljeSpecDokTipDataGridViewCellValueNeeded);
			this.uxDokumentZaglavljeSpecDokTipDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnDokumentZaglavljeSpecDokTipDataGridViewCellValuePushed);
			
			//
			// uxIDDataGridViewColumn
			//
			this.uxIDDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDDataGridViewColumn.DataPropertyName = "ID";
			this.uxIDDataGridViewColumn.HeaderText = "ID";
			this.uxIDDataGridViewColumn.Name = "uxIDDataGridViewColumn";
			this.uxIDDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDDataGridViewColumn.ReadOnly = true;		
			//
			// uxIDDokumentTipOdDataGridViewColumn
			//
			this.uxIDDokumentTipOdDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDDokumentTipOdDataGridViewColumn.DataPropertyName = "IDDokumentTipOd";
			this.uxIDDokumentTipOdDataGridViewColumn.HeaderText = "IDDokumentTipOd";
			this.uxIDDokumentTipOdDataGridViewColumn.Name = "uxIDDokumentTipOdDataGridViewColumn";
			this.uxIDDokumentTipOdDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDDokumentTipOdDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDDokumentTipOdDataGridViewColumn.ReadOnly = false;		
			//
			// uxIDDokumentTipZaDataGridViewColumn
			//
			this.uxIDDokumentTipZaDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDDokumentTipZaDataGridViewColumn.DataPropertyName = "IDDokumentTipZa";
			this.uxIDDokumentTipZaDataGridViewColumn.HeaderText = "IDDokumentTipZa";
			this.uxIDDokumentTipZaDataGridViewColumn.Name = "uxIDDokumentTipZaDataGridViewColumn";
			this.uxIDDokumentTipZaDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDDokumentTipZaDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDDokumentTipZaDataGridViewColumn.ReadOnly = false;		
			//
			// uxIDDokumentTipOdDataGridViewColumn
			//				
			this.uxIDDokumentTipOdDataGridViewColumn.DisplayMember = "Naziv";	
			this.uxIDDokumentTipOdDataGridViewColumn.ValueMember = "ID";	
			this.uxIDDokumentTipOdDataGridViewColumn.DisplayStyleForCurrentCellOnly = true;
			//uxIDDokumentTipOdDataGridViewColumn.DataSource = uxIDDokumentTipOdBindingSource;				
				
			//
			// uxIDDokumentTipZaDataGridViewColumn
			//				
			this.uxIDDokumentTipZaDataGridViewColumn.DisplayMember = "Naziv";	
			this.uxIDDokumentTipZaDataGridViewColumn.ValueMember = "ID";	
			this.uxIDDokumentTipZaDataGridViewColumn.DisplayStyleForCurrentCellOnly = true;
			//uxIDDokumentTipZaDataGridViewColumn.DataSource = uxIDDokumentTipZaBindingSource;				
				
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxDokumentZaglavljeSpecDokTipDataGridView);
			this.Name = "DokumentZaglavljeSpecDokTipDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDDokumentTipOdBindingSource)).EndInit();
			//((System.ComponentModel.ISupportInitialize)(this.uxIDDokumentTipZaBindingSource)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentZaglavljeSpecDokTipErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentZaglavljeSpecDokTipDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentZaglavljeSpecDokTipBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				DokumentZaglavljeSpecDokTipDataGridViewEventArgs args = new DokumentZaglavljeSpecDokTipDataGridViewEventArgs();
				args.DokumentZaglavljeSpecDokTip = _currentDokumentZaglavljeSpecDokTip;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class DokumentZaglavljeSpecDokTipDataGridViewEventArgs : System.EventArgs
		{
			private Entities.DokumentZaglavljeSpecDokTip	_DokumentZaglavljeSpecDokTip;
	
			/// <summary>
			/// the  Entities.DokumentZaglavljeSpecDokTip instance.
			/// </summary>
			public Entities.DokumentZaglavljeSpecDokTip DokumentZaglavljeSpecDokTip
			{
				get { return _DokumentZaglavljeSpecDokTip; }
				set { _DokumentZaglavljeSpecDokTip = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxDokumentZaglavljeSpecDokTipDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnDokumentZaglavljeSpecDokTipDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxDokumentZaglavljeSpecDokTipDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnDokumentZaglavljeSpecDokTipDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxDokumentZaglavljeSpecDokTipDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDDataGridViewColumn":
						e.Value = DokumentZaglavljeSpecDokTipList[e.RowIndex].ID;
						break;
					case "uxIDDokumentTipOdDataGridViewColumn":
						e.Value = DokumentZaglavljeSpecDokTipList[e.RowIndex].IDDokumentTipOd;
						break;
					case "uxIDDokumentTipZaDataGridViewColumn":
						e.Value = DokumentZaglavljeSpecDokTipList[e.RowIndex].IDDokumentTipZa;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxDokumentZaglavljeSpecDokTipDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnDokumentZaglavljeSpecDokTipDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxDokumentZaglavljeSpecDokTipDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDDataGridViewColumn":
						DokumentZaglavljeSpecDokTipList[e.RowIndex].ID = (System.Int32)e.Value;
						break;
					case "uxIDDokumentTipOdDataGridViewColumn":
						DokumentZaglavljeSpecDokTipList[e.RowIndex].IDDokumentTipOd = (System.Int32)e.Value;
						break;
					case "uxIDDokumentTipZaDataGridViewColumn":
						DokumentZaglavljeSpecDokTipList[e.RowIndex].IDDokumentTipZa = (System.Int32)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
